﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;
using System.Text;
using System.Xml;

public partial class Manager_OrderApp_OrderApp_v1 : System.Web.UI.Page
{
    protected object sData = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminUserID"] == null)
        {
            Response.Write("<script language=javascript>alert('Time is out.');window.open('../Default.aspx','_top');</script>");
            return;
        }

        Ajax.Utility.RegisterTypeForAjax(typeof(Manager_OrderApp_OrderApp_v1));

        fnSearch();
        if (!IsPostBack)
        {
            BindPlace();
            BindData();
        }
        else
        {
            string xml = "<PccMsg>" + hMethod.Value + "</PccMsg>";
            PccMsg msg = new PccMsg(xml);
            if (msg.Query("Method").ToUpper() == "CHOOSEUSER")
            {
                BindGuest_Info(msg.Query("UserID"));
                BindData();
                hMethod.Value = "";
            }
            else if (msg.Query("Method").ToUpper() == "SAVE")
            {
                SaveData(msg);
                BindData();
                hMethod.Value = "";
            }
        }
    }

    private void BindGuest_Info(string UserID)
    {

        txtDiaChi.ReadOnly = false;
        txtDienThoai.ReadOnly = false;
        txtEmail.ReadOnly = false;
        txtHoTen.ReadOnly = false;
        txtTaxNo.ReadOnly = false;
        ddlPlace.Enabled = true;
        txtTaxNo.BackColor = System.Drawing.Color.White;
        txtHoTen.BackColor = System.Drawing.Color.White;
        txtEmail.BackColor = System.Drawing.Color.White;
        txtDienThoai.BackColor = System.Drawing.Color.White;
        txtDiaChi.BackColor = System.Drawing.Color.White;

        clsWebShop cls = new clsWebShop();
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("UserID", UserID);
        DataTable dt = new DataTable();
        dt = cls.Get_shr_UserByUserID(msg.GetXmlStr.ToString()).Tables[0];
        if (dt.Rows.Count > 0)
        {
            string CusNm = dt.Rows[0]["CusNm"].ToString();
            string Address = dt.Rows[0]["Address"].ToString();
            string Phone = dt.Rows[0]["Phone"].ToString();
            string Email = dt.Rows[0]["Email"].ToString();
            string PlaceNm = dt.Rows[0]["PlaceNm"].ToString();
            string PlaceID = dt.Rows[0]["PlaceID"].ToString();
            string TaxNo = dt.Rows[0]["TaxNo"].ToString();
            txtHoTen.Text = CusNm.Trim();
            txtDiaChi.Text = Address.Trim();
            txtDienThoai.Text = Phone.Trim();
            txtEmail.Text = Email.Trim();
            txtTaxNo.Text = TaxNo.Trim();
            ddlPlace.SelectedItem.Selected = false;
            ddlPlace.Items.FindByValue(PlaceID).Selected = true;
        }
    }

    #region fnSearch

    private void BindPlace()
    {
        clsWebShop cls = new clsWebShop();
        ddlPlace.DataSource = cls.Get_PlaceNoneProc();
        ddlPlace.DataTextField = "PlaceNm";
        ddlPlace.DataValueField = "PlaceID";
        ddlPlace.DataBind();
        ListItem item = new ListItem();
        item.Text = "---";
        item.Value = "";
        ddlPlace.Items.Insert(0, item);

        lblUSD.Text = "Tỉ giá USD: " + FormatMoney(cls.GetMoney("USD")) + " VNĐ";
        hidUSD.Value = cls.GetMoney("USD").ToString();


    }

    private void fnSearch()
    {
        clsWebShop cls = new clsWebShop();
        DataTable dt;
        dt = cls.GetData("select rtrim(PDName)PDName,PDID,Price,Rate,KindNo from Product p inner join Catalogue c  on p.catid=c.catid where p.Status<>'D'  " + " and c.Status<>'D'").Tables[0];
        sData = CreateJsonParameters(dt);
    }
    public string CreateJsonParameters(DataTable dt)
    {
        StringBuilder JsonString = new StringBuilder();

        //Exception Handling
        if (dt != null && dt.Rows.Count > 0)
        {
            JsonString.Append("[ ");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                JsonString.Append("{ ");
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    if (j < dt.Columns.Count - 1)
                    {
                        JsonString.Append("\"" + dt.Columns[j].ColumnName.ToString() +
                              "\":" + "\"" +
                              ReplaceBadChar(dt.Rows[i][j].ToString()) + "\",");
                    }
                    else if (j == dt.Columns.Count - 1)
                    {
                        JsonString.Append("\"" +
                           dt.Columns[j].ColumnName.ToString() + "\":" +
                           "\"" + ReplaceBadChar(dt.Rows[i][j].ToString()) + "\"");
                    }
                }
                /*end Of String*/
                if (i == dt.Rows.Count - 1)
                {
                    JsonString.Append("} ");
                }
                else
                {
                    JsonString.Append("}, ");
                }
            }
            JsonString.Append("]");
            return JsonString.ToString();
        }
        else
        {
            return null;
        }
    }

    private string ReplaceBadChar(string str)
    {
        return str.Replace(@"\","").Replace("[","").Replace("]","").Replace("'","").Replace("\"","");
    }

    #endregion

    private void BindData()
    {
        grvMaster.DataSource = GetData();
        grvMaster.DataBind();
    }

    private void SaveData(PccMsg myMsg)
    {
        PccMsg msg = new PccMsg();
        clsWebShop cls = new clsWebShop();
        clsCommon clsCom = new clsCommon();

        if (hUserExc.Value != "" && hUserExc.Value != "0")
        {
            //Them user
            msg.CreateFirstNode("UserID", clsCom.ConvertToDecimal(hUserExc.Value).ToString());
            msg.CreateFirstNode("AutID", "0");
            msg.CreateFirstNode("CusNm", txtHoTen.Text);
            msg.CreateFirstNode("AccountID", "");
            msg.CreateFirstNode("Address", txtDiaChi.Text);
            msg.CreateFirstNode("PlaceID", clsCom.ConvertToDecimal(ddlPlace.SelectedValue).ToString());
            msg.CreateFirstNode("Phone", txtDienThoai.Text);
            msg.CreateFirstNode("Email", txtEmail.Text);
            msg.CreateFirstNode("TaxNo", txtTaxNo.Text.Trim());
            cls.Upd_shr_UserOrder(msg.GetXmlStr.ToString());
            //Them vao OrderPD
            msg = new PccMsg();
            msg.CreateFirstNode("UserID", hUserExc.Value);
            msg.CreateFirstNode("Status", "S");
            msg.CreateFirstNode("Repaid", clsCom.ConvertToDecimal(txtRepaid.Text.Replace(",", "")).ToString());
            msg.CreateFirstNode("RemainPrice", clsCom.ConvertToDecimal(txtRemainPrice.Text.Replace(",", "")).ToString());
            msg.CreateFirstNode("Note", txtNote.Text);
            msg.CreateFirstNode("USD", clsCom.ConvertToDecimal(hidUSD.Value).ToString());
            msg.CreateFirstNode("UpdID", Session["AdminUserID"].ToString());
            msg.CreateFirstNode("Note_MK", "SOLD ADMIN");
            string sDateTime = System.DateTime.Now.ToString("yyyyMMddhhmmss");
            string strReXML = "";
            strReXML = cls.Ins_OrderPD(msg.GetXmlStr.ToString());
            //Them vao OrderDetail
            msg = new PccMsg(strReXML);
            string OrderIDMsg = msg.Query("OrderIDMsg");
            if (OrderIDMsg != "")
            {
                try
                {
                    XmlNodeList node = myMsg.QueryNodes("OrderDetail");

                    for (int i = 0; i < node.Count; i++)
                    {

                        string Price = node[i].SelectSingleNode("PRICE").InnerText.Replace(",", "");
                        string PriceSaleOf = node[i].SelectSingleNode("PRICESALEOFF").InnerText.Replace(",", "");
                        string OldPrice = Price;
                        string Quantity = node[i].SelectSingleNode("QUANTITY").InnerText.Replace(",", "");
                        decimal OldTotal = clsCom.ConvertToDecimal(Price) * clsCom.ConvertToDecimal(Quantity);
                        if (PriceSaleOf != "" && PriceSaleOf != "0")
                        {
                            Price = PriceSaleOf;
                        }

                        msg = new PccMsg();
                        msg.CreateFirstNode("OrderID", OrderIDMsg);
                        msg.CreateFirstNode("PDID", node[i].SelectSingleNode("PDID").InnerText);
                        msg.CreateFirstNode("StId", "");
                        msg.CreateFirstNode("Rate", node[i].SelectSingleNode("RATE").InnerText);
                        msg.CreateFirstNode("Quantity", Quantity);
                        msg.CreateFirstNode("Price", clsCom.ConvertToDecimal(Price).ToString());
                        msg.CreateFirstNode("OldPrice", clsCom.ConvertToDecimal(OldPrice.Replace(",", "")).ToString());
                        msg.CreateFirstNode("Total", clsCom.ConvertToDecimal(node[i].SelectSingleNode("TOTAL").InnerText.Replace(",", "")).ToString());
                        msg.CreateFirstNode("OldTotal", OldTotal.ToString());
                        msg.CreateFirstNode("NoteDetail", node[i].SelectSingleNode("NOTEDETAIL").InnerText);
                        msg.CreateFirstNode("UpdID", Session["AdminUserID"].ToString());
                        string strXml = cls.Ins_SendOrderDetail(msg.GetXmlStr);

                    }

                    //INSERT FLOWORDERHIST
                    clsFunAp clsFun = new clsFunAp();

                    msg = new PccMsg();
                    msg.CreateFirstNode("OrderID", OrderIDMsg);
                    msg.CreateFirstNode("SignUser", Session["AdminUserID"].ToString());
                    msg.CreateFirstNode("Status", "S");
                    msg.CreateFirstNode("Note", clsFun.NoteTo_Y(txtPaidMoney.Text.Replace(",", ""), txtRemainPrice.Text.Replace(",", ""), " VNĐ"));

                    cls.Ins_Upd_FlowOrderHist(msg.GetXmlStr);

                    //SEND MAIL
                    SendMailBasket(OrderIDMsg, node);
                    ///Ket thuc dat hang

                    ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('Đã đặt hàng thành công');window.location.href='../OrderDetail/OrderDetail.aspx?IsPrint=" + hPrintPage.Value + "&sState=S&CodeID=" + Request.QueryString["CodeID"] + "&sOrderID=" + OrderIDMsg + "'</script>");

                }
                catch
                {
                    cls.UpdateData("Delete from OrderPD Where OrderID='" + OrderIDMsg + "'       Delete from OrderDetail Where OrderID='" + OrderIDMsg + "'");
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('Có lỗi tạo đơn đặt hàng')</script>");
                    BindData();
                }
            }
        }
        else
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('Chọn khách hàng cho đơn đặt hàng của bạn')</script>");
            BindData();
            return;
        }
    }



    private void SendMailBasket(string OrderID, XmlNodeList node)
    {
        string HTML = "", result = "";
        if (node.Count > 0)
        {
            HTML += " <table border='0' bordercolor='#407db3' cellpadding='2' cellspacing='0' style='border-collapse: collapse;'   width='100%'>";
            HTML += "             <tr>";
            HTML += "                 <td align='center' colspan='4'>";
            HTML += "                      <table border='0' cellpadding='0' cellspacing='0' style='width: 100%'>";
            HTML += "    <tr>";
            HTML += " <td rowspan='5' style='width: 76px'>";
            HTML += " <img src='" + System.Configuration.ConfigurationManager.AppSettings["AppAddress"] + "/Images/Banner/logo.png' /></td>";
            HTML += " <td align='left'>";
            HTML += " &nbsp;<span id='Label11'  style='ont-family:Tahoma; font-size:13px'>Công ty TNHH Hoàng Nguyên Bảo</span>";
            HTML += " </td>";
            HTML += " </tr>";
            HTML += " <tr>";
            HTML += " <td align='left'>";
            HTML += " &nbsp;<span id='Label18' style='ont-family:Tahoma; font-size:13px'>MST: 0309543650</span></td>";
            HTML += " </tr>";
            HTML += " <tr>";
            HTML += " <td align='left'>";
            HTML += " &nbsp;<span id='Label12' style='ont-family:Tahoma; font-size:13px'>16/83 Nguyễn Thiện Thuật P2 Q3</span></td>";
            HTML += " </tr>";
            HTML += " <tr>";
            HTML += " <td align='left'>";
            HTML += " &nbsp;<span id='Label16' style='ont-family:Tahoma; font-size:13px'>Tel: (08)62909078-62909079 Cel:098.2600917</span></td>";
            HTML += " </tr>";
            HTML += " </table>";
            HTML += " </td>";
            HTML += " </tr>";
            HTML += " <tr>";
            HTML += " <td colspan='4' align='center' valign='top' style='height: 31px'>";
            HTML += " <span id='Label2' style='font-family: Tahoma; font-size: 13pt; font-weight: bold;'>";
            HTML += " CHI TIẾT ĐƠN ĐẶT HÀNG</span></td>";
            HTML += " </tr>";
            HTML += " <tr>";
            HTML += " <td align='right' colspan='4' valign='bottom'>";
            HTML += " <table border='0' cellpadding='0' cellspacing='0'>";
            HTML += " <tr>";
            HTML += " <td align='left'>";
            HTML += " Mã đơn hàng</td>";
            HTML += " <td align='left' valign='middle' style='white-space: nowrap'>";
            HTML += " :&nbsp;<span id='lblMaDH' style='font-weight: bold;'>" + OrderID + "</span></td>";
            HTML += " </tr>";
            HTML += " </table>";
            HTML += " </td>";
            HTML += " </tr>";
            HTML += " <tr>";
            HTML += " <td colspan='4'>";
            HTML += " <div style='border-style:dotted; border-width:1px;'>";
            HTML += " <table id='AutoNumber1' style='border-right: 1px solid; padding-right: 0px; border-top: 1px solid; padding-left: 0px; padding-bottom: 0px; border-left: 1px solid; padding-top: 1px; border-bottom: 1px solid; border-collapse: collapse'    bordercolor='#111111' cellspacing='0'                cellpadding='2' width='100%'>";
            HTML += " <tr>";
            HTML += " <td  nowrap style='padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;   border-bottom: 1px dotted; width: 110px;' align='left' nowrap>";
            HTML += " Tên khách hàng</td>";
            HTML += " <td align='left' colspan='3' nowrap='nowrap' style='padding-right: 4px; padding-left: 4px;     padding-bottom: 1px; padding-top: 1px; border-bottom: 1px dotted'>";
            HTML += " :&nbsp;<span id='lblTenKH'>" + txtHoTen.Text + "</span></td>";
            HTML += " </tr>";
            HTML += " <tr>";
            HTML += " <td nowrap style='padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px; border-bottom: 1px dotted; width: 95px;' align='left'>";
            HTML += " Địa chỉ</td>";
            HTML += " <td nowrap style='padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px; border-bottom: 1px dotted' align='left'>";
            HTML += " :&nbsp;<span id='lblDiaChi'>" + txtDiaChi.Text + "</span></td>";
            HTML += " <td nowrap style='padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;         border-bottom: 1px dotted; width: 114px;' align='left'>";
            HTML += " Tỉnh, Thành Phố</td>";
            HTML += " <td nowrap style='padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;   border-bottom: 1px dotted' align='left'>";
            HTML += " :&nbsp;<span id='lblNoichon'>" + ddlPlace.SelectedItem.Text + "</span></td>";
            HTML += " </tr>";
            if (txtTaxNo.Text.Trim() != "")
            {
                HTML += " <tr>";
                HTML += " <td nowrap style='padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;   border-bottom: 1px dotted; width: 95px;' align='left'>";
                HTML += " Mã số thuế</td>";
                HTML += " <td align='left' colspan='3' nowrap='nowrap' style='padding-right: 4px; padding-left: 4px;     padding-bottom: 1px; padding-top: 1px; border-bottom: 1px dotted'>";
                HTML += " :&nbsp;<span id='lblTenKH'>" + txtTaxNo.Text + "</span></td>";
                HTML += " </tr>";
            }

            HTML += " <tr>";
            HTML += " <td nowrap style='padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;   width: 95px;' align='left'>";
            HTML += " Điện thoại</td>";
            HTML += " <td nowrap style='padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;   align='left'>";
            HTML += " :&nbsp;<span id='lblSDT'>" + txtDienThoai.Text + " </span>";
            HTML += " </td>";
            HTML += " <td nowrap style='padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;    width: 114px;' align='left'>";
            HTML += " Email</td>";
            HTML += " <td nowrap style='padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;    align='left'>";
            HTML += " :&nbsp;<span id='lblEmail'>" + txtEmail.Text + "</span></td>";
            HTML += " </tr>";
            HTML += " </table>";
            HTML += " </td>";
            HTML += " </tr>";
            HTML += "   <tr>";
            HTML += "  <td>";
            HTML += "     </td>";
            HTML += "    <td>";
            HTML += "    </td>";
            HTML += " <td>";
            HTML += "  </td>";
            HTML += "   <td>";
            HTML += "  </td>";
            HTML += "  </tr>";

            HTML += "   </table>";
            HTML += "   </div>";

            //================================================= danh sach san pham
            HTML += " <div width='100%' align='right'>";
            HTML += lblUSD.Text;
            HTML += "<table border='1' cellpadding='3' cellspacing='0' style='width: 100%;border-collapse:collapse' bordercolor='#407db3'>";
            //Header
            HTML += "<tr height='30px' style='BACKGROUND-COLOR: #D8ECFF;font-family:Tahoma;font-size:13px;'>";
            HTML += "<th width='2%' nowrap>Mã sản phẩm</th>";
            HTML += "<th align='left'>" + ((System.Web.UI.WebControls.DataControlFieldCell)(grvMaster.Rows[0].Cells[2])).ContainingField.HeaderText + "</th>";
            HTML += "<th   width='2%' nowrap>" + ((System.Web.UI.WebControls.DataControlFieldCell)(grvMaster.Rows[0].Cells[3])).ContainingField.HeaderText + "</th>";
            HTML += "<th   width='10%' nowrap>" + ((System.Web.UI.WebControls.DataControlFieldCell)(grvMaster.Rows[0].Cells[4])).ContainingField.HeaderText + "</th>";
            HTML += "<th  width='10%' nowrap>" + ((System.Web.UI.WebControls.DataControlFieldCell)(grvMaster.Rows[0].Cells[6])).ContainingField.HeaderText + "</th>";//thanh tien
            HTML += "<th  width=10%' nowrap>" + ((System.Web.UI.WebControls.DataControlFieldCell)(grvMaster.Rows[0].Cells[7])).ContainingField.HeaderText + "</th>"; //ghi chu
            HTML += "</tr>";
            //Row
            for (int i = 0; i < node.Count; i++)
            {
                if (i % 2 == 0)
                    HTML += "<tr style='BACKGROUND-COLOR: #feffeb;font-family:Tahoma;font-size:12px;'>";
                else
                    HTML += "<tr style='BACKGROUND-COLOR: #ffffff;font-family:Tahoma;font-size:12px;'>";


                HTML += "<td align='center'  nowrap><a  href='" + System.Configuration.ConfigurationManager.AppSettings["AppAddress"].ToString() + "/Shopping/Stall/ProductDetail.aspx?PDID=" + node[i].SelectSingleNode("PDID").InnerText + "'>" + node[i].SelectSingleNode("PDID").InnerText + "</a></td>";
                HTML += "<td>" + node[i].SelectSingleNode("PDNAME").InnerText + "</td>";
                HTML += "<td align='center' nowrap>" + node[i].SelectSingleNode("QUANTITY").InnerText + "</td>";
                HTML += "<td align='right'  nowrap>" + node[i].SelectSingleNode("PRICE").InnerText + " " + node[i].SelectSingleNode("RATE").InnerText + "</td>";
                HTML += "<td align='right'  nowrap>" + node[i].SelectSingleNode("TOTAL").InnerText + "</td>";
                HTML += "<td align='center'  nowrap>" + node[i].SelectSingleNode("NOTEDETAIL").InnerText + "</td>";


                HTML += "</tr>";
            }
            

            HTML += "</table>";
            HTML += "</div>";
            HTML += "<br>";


            //Footer
            HTML += " <table border='0' bordercolor='#407db3' cellpadding='2' cellspacing='0' style='border-collapse: collapse;'   width='100%'>";
            HTML += "<tr>";
            HTML += "    <td align='center' valign='top'>";
            HTML += "        <table style='border-collapse: collapse;' border='0' bordercolor='#407db3' cellpadding='0' cellspacing='0'>";
            HTML += "            <tbody><tr>";
            HTML += "                <td style='padding-right: 10px; white-space: nowrap;' align='right' valign='bottom'>";
            HTML += "                    <span id='ctl00_ContentPlaceHolder1_Label14' style='font-weight: bold;font-family: tahoma; font-size: 13px;'>Tổng số lượng: </span></td>";
            HTML += "                <td colspan='2' style='border-bottom: thin dotted black; width: 160px; white-space: nowrap;' align='right' valign='bottom'>";
            HTML += "                    <span id='ctl00_ContentPlaceHolder1_lblQuantity' style='font-family: tahoma; font-size: 13px;'>" + lblQuantity.Text + "</span></td>";
            HTML += "                <td style='width: 2%; white-space: nowrap;' align='right'>";
            HTML += "                </td>";
            HTML += "                <td id='ctl00_ContentPlaceHolder1_td1' style='padding-right: 10px; white-space: nowrap;' align='right' valign='bottom'>";
            HTML += "                   <span id='ctl00_ContentPlaceHolder1_Label4' style='font-weight: bold;font-family: tahoma; font-size: 13px;'>Số tiền đã trả:</span></td>";
            HTML += "                <td id='ctl00_ContentPlaceHolder1_td2' style='border-bottom: thin dotted black; width: 160px; white-space: nowrap;' align='right' valign='bottom'>";
            HTML += "                    <span id='ctl00_ContentPlaceHolder1_lblRepaid' style='font-family: tahoma; font-size: 13px;'>" + txtRepaid.Text + "</span>";
            HTML += "                    <span id='ctl00_ContentPlaceHolder1_Label9' style='font-family: tahoma; font-size: 13px;'>VNĐ</span>&nbsp;";
            HTML += "                </td>";
            HTML += "            </tr>";
            HTML += "            <tr>";
            HTML += "                <td style='padding-right: 10px; white-space: nowrap;' align='right' valign='bottom'>";
            HTML += "                    <span id='ctl00_ContentPlaceHolder1_Label15' style='font-weight: bold;font-family: tahoma; font-size: 13px;'>Tổng số tiền thanh toán: </span></td>";
            HTML += "                <td colspan='2' style='border-bottom: thin dotted black; white-space: nowrap;' align='right' valign='bottom'>";
            HTML += "                    <span id='ctl00_ContentPlaceHolder1_lblTotal' style='font-family: tahoma; font-size: 13px;'>" + lblTongsotien.Text + "</span>";
            HTML += "                    <span id='ctl00_ContentPlaceHolder1_Label6' style='font-family: tahoma; font-size: 13px;'>VNĐ</span>&nbsp;</td>";
            HTML += "                <td style='width: 2%; white-space: nowrap;' align='right'>";
            HTML += "                </td>";
            HTML += "                <td id='ctl00_ContentPlaceHolder1_td3' style='padding-right: 10px; white-space: nowrap;' align='right' valign='bottom'>";
            HTML += "                    <span id='ctl00_ContentPlaceHolder1_Label5' style='font-weight: bold;font-family: tahoma; font-size: 13px;'>Số tiền còn thiếu lại:</span></td>";
            HTML += "                <td id='ctl00_ContentPlaceHolder1_td4' style='border-bottom: thin dotted black; white-space: nowrap;' align='right' valign='bottom'>";
            HTML += "                    <span id='ctl00_ContentPlaceHolder1_lblRemainPrice' style='font-family: tahoma; font-size: 13px;'>" + txtRemainPrice.Text + "</span>";
            HTML += "                    <span id='ctl00_ContentPlaceHolder1_Label11' style='font-family: tahoma; font-size: 13px;'>VNĐ</span>&nbsp;";
            HTML += "                </td>";
            HTML += "";
            HTML += "            </tr>";
            HTML += "        </tbody></table>";
            HTML += "    </td>";
            HTML += "</tr>";
            if (txtNote.Text.Trim() != "")
            {
                HTML += "<tr>";
                HTML += "    <td align='left' valign='top'>";
                HTML += "        <table border='0' cellpadding='0' cellspacing='0'>";
                HTML += "            <tbody><tr>";
                HTML += "               <td style='border-bottom: thin dotted black;'>";
                HTML += "                    <span id='ctl00_ContentPlaceHolder1_lblChuY' style='font-weight: bold;'>Ghi chú: </span>";
                HTML += "                   <span id='ctl00_ContentPlaceHolder1_lblNote'>" + txtNote.Text + "</span></td>";
                HTML += "            </tr>";
                HTML += "        </tbody></table>";
                HTML += "    </td>";
                HTML += "</tr>";
            }
            HTML += "</table>";


            HTML += "<br>";
            HTML += "Thank you to  my website: <a  href='http://" + System.Configuration.ConfigurationManager.AppSettings["AppAddress"].ToString() + "'>" + System.Configuration.ConfigurationManager.AppSettings["AppAddress"].ToString() + "</a>";

            clsCommon clsCom = new clsCommon();
            result = clsCom.Send_AppEmail(System.Configuration.ConfigurationManager.AppSettings["SaleMail"].ToString(), txtEmail.Text, System.Configuration.ConfigurationManager.AppSettings["SaleMail"].ToString() + ";" + System.Configuration.ConfigurationManager.AppSettings["WebMail"].ToString(), "Chi tiet Don Dat hang(" + System.DateTime.Now.ToString("dd/MM/yyyy  hh:mm:ss") + ")", HTML);
        }

    }


    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        if (dt.Rows.Count <= 0)
        {
            DataRow dr = dt.NewRow();
            dt.Rows.Add(dr);
        }
        return dt;
    }

    private string FormatMoney(decimal dNum)
    {
        string sReturn = "0";
        try
        {
            sReturn = string.Format("{0:###,###,##0}", dNum);
        }
        catch (Exception) { }
        return sReturn;
    }
    [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
    public string AjaxCheckEmail(string value, string ExcUser)
    {

        string flag = "no";
        clsWebShop cls = new clsWebShop();
        DataTable dt = new DataTable();
        PccMsg msg = new PccMsg();

        msg.CreateFirstNode("ExcUserID", ExcUser);
        msg.CreateFirstNode("Email", value.Trim());
        dt = cls.Get_shr_UserByUserEmail(msg.GetXmlStr.ToString()).Tables[0];
        if (dt.Rows.Count > 0)
            flag = "yes";
        return flag;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("OrderApp_v1.aspx");
    }
}
